package org.gd.hellojson.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.gd.hellojaxb.privat24.statements.Statements;
import org.gd.hellojson.jackson.JacksonUser;

import java.util.Locale;

public class GsonToExample {

    private static Gson gsonDate = new GsonBuilder()
            .setDateFormat("yyyy:MM:dd HH:mm:ss")
            .registerTypeAdapter(GsonJsonSerializer.class, new GsonJsonSerializer("yyyy:MM:dd", new Locale("UA")))
            .create();

    public static void main(String[] args) {

        /*String json = gson.toJson(new DataObject().addToList("add1").addToList("add2"));*/
        /*String json = gson.toJson(new GsonTestUser("user name", "user login"));*/

        GsonUser user = new GsonUser("name", "login");
        String json = gsonDate.toJson(user);
        System.out.println(json
                .replace("{", "{\n\t")
                .replace(",", ",\n\t")
                .replace("}", "\n}")
        );

        user = gsonDate.fromJson(json, GsonUser.class);
        System.out.println("------------------------------");
        System.out.println(user.getLogin());
        System.out.println(user.getName());
        System.out.println(user.getDate());
        System.out.println("------------------------------");
        System.out.println(gsonDate.toJson(new Statements()));
        System.out.println("------------------------------");
        System.out.println(gsonDate.toJson(new JacksonUser()));

        /*try {
            FileWriter writer = new FileWriter("file.json");
            writer.write(json);
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }*/
    }
}
